﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using Maticsoft.Common;
using LTP.Accounts.Bus;

namespace Maticsoft.Web.sysMan
{
    public partial class ModifyAnswer : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                if (Request.Params["id"] != null && Request.Params["id"].Trim() != "")
                {
                    int aid = (Convert.ToInt32(Request.Params["id"]));
                    ShowInfo(aid);
                }
            }
        }

        private void ShowInfo(int aid)
        {
            Maticsoft.BLL.answerinfo bll = new Maticsoft.BLL.answerinfo();
            Maticsoft.Model.answerinfo model = bll.GetModel(aid);
            this.lblaid.Text = model.aid.ToString();
            this.txtjtitle.Text = model.ainfo;
            this.txtjkey.Text = model.akey;
            this.txtjscore.Text = model.ascore.ToString();
            this.txtstuType.Text = model.stuType;

        }

        public void btnSave_Click(object sender, EventArgs e)
        {

            string strErr = "";
            if (this.txtjtitle.Text.Trim().Length == 0)
            {
                strErr += "问答题标题不能为空！\\n";
            }
            if (this.txtjkey.Text.Trim().Length == 0)
            {
                strErr += "答案不能为空！\\n";
            }
            if (!PageValidate.IsDecimal(txtjscore.Text))
            {
                strErr += "分值格式错误！\\n";
            }
            //if (this.txtstuType.Text.Trim().Length == 0)
            //{
            //    strErr += "stuType不能为空！\\n";
            //}

            if (strErr != "")
            {
                MessageBox.Show(this, strErr);
                return;
            }
            int aid = int.Parse(this.lblaid.Text);
            string ainfo = this.txtjtitle.Text;
            string akey = this.txtjkey.Text;
            decimal ascore = decimal.Parse(this.txtjscore.Text);
            string stuType = this.txtstuType.Text;


            Maticsoft.Model.answerinfo model = new Maticsoft.Model.answerinfo();
            model.aid = aid;
            model.ainfo = ainfo;
            model.akey = akey;
            model.ascore = ascore;
            model.stuType = stuType;

            Maticsoft.BLL.answerinfo bll = new Maticsoft.BLL.answerinfo();
            bll.Update(model);
            Maticsoft.Common.MessageBox.ShowAndRedirect(this, "保存成功！", "ListAnswerInfo.aspx");

        }
    }
}